package co.fitstart.entity.report;

import java.beans.Transient;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import co.fitstart.entity.site.Site;

@Entity
@Table(name = "visitor_report")
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class VisitorReport {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /** 访客数 */
    private long visitAmount;
    
    /** 参与体验课数 */
    private long experienceAmount;
    
    /** 教练排体验课数 */
    private long coachExperienceAmount;
    
    /** 下单数 */
    private long orderedAmount;
    
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @org.hibernate.annotations.Type(type = "date")
    private Date occurDate;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    private Site site;
    
    /**
     * The default constructor
     */
    public VisitorReport() {
        
    }
    
    /**
     * 
     * @param visitAmount
     * @param experienceAmount
     * @param coachExperienceAmount
     * @param orderedAmount
     * @param site
     */
    public VisitorReport(long visitAmount, long experienceAmount, long coachExperienceAmount, long orderedAmount, Site site) {
        this.visitAmount = visitAmount;
        this.experienceAmount = experienceAmount;
        this.coachExperienceAmount = coachExperienceAmount;
        this.orderedAmount = orderedAmount;
        this.site = site;
    }
    
    /**
     * 
     * @param visitAmount
     * @param experienceAmount
     * @param coachExperienceAmount
     * @param orderedAmount
     * @param occurDate
     * @param site
     */
    public VisitorReport(long visitAmount, long experienceAmount, long coachExperienceAmount, long orderedAmount, Date occurDate, Site site) {
        this.visitAmount = visitAmount;
        this.experienceAmount = experienceAmount;
        this.coachExperienceAmount = coachExperienceAmount;
        this.orderedAmount = orderedAmount;
        this.occurDate = occurDate;
        this.site = site;
    }
    
    /**
     * 
     * @param visitAmount
     * @param experienceAmount
     * @param coachExperienceAmount
     * @param orderedAmount
     */
    public VisitorReport(long visitAmount, long experienceAmount, long coachExperienceAmount, long orderedAmount) {
        this.visitAmount = visitAmount;
        this.experienceAmount = experienceAmount;
        this.coachExperienceAmount = coachExperienceAmount;
        this.orderedAmount = orderedAmount;
    }
    
    /**
     * 
     * @param site
     * @param experienceAmount
     * @param coachExperienceAmount
     * @param orderedAmount
     * @param occurDate
     * @return
     */
    public VisitorReport initilization(Site site, long experienceAmount, long coachExperienceAmount, long orderedAmount, Date occurDate) {
        this.visitAmount = 0;
        this.experienceAmount = experienceAmount;
        this.coachExperienceAmount = coachExperienceAmount;
        this.orderedAmount = orderedAmount;
        this.occurDate = occurDate;
        this.site = site;
        return this;
    }
    
    /**
     * 
     * @param experienceAmount
     * @return
     */
    public VisitorReport editExperienceAmount(long experienceAmount) {
        this.experienceAmount = experienceAmount;
        return this;
    }
    
    /**
     * 
     * @param coachExperienceAmount
     * @return
     */
    public VisitorReport editCoachExperienceAmount(long coachExperienceAmount) {
        this.coachExperienceAmount = coachExperienceAmount;
        return this;
    }
    
    /**
     * 
     * @param orderedAmount
     * @return
     */
    public VisitorReport editOrderedAmount(long orderedAmount) {
        this.orderedAmount = orderedAmount;
        return this;
    }
    
    /**
     * 
     * @param visitAmount
     * @return
     */
    public VisitorReport editVisitAmount(long visitAmount) {
        this.visitAmount = visitAmount;
        return this;
    }
    
    /**
     * 
     * @return
     */
    @Transient
    public BigDecimal getConversion() {
        long experience = experienceAmount + coachExperienceAmount;
        return experience == 0 ? new BigDecimal(0) : new BigDecimal(orderedAmount).multiply(new BigDecimal(100)).divide(new BigDecimal(experienceAmount + coachExperienceAmount), 2, RoundingMode.CEILING);
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the visitAmount
     */
    public long getVisitAmount() {
        return visitAmount;
    }

    /**
     * @return the experienceAmount
     */
    public long getExperienceAmount() {
        return experienceAmount;
    }

    /**
     * @return the coachExperienceAmount
     */
    public long getCoachExperienceAmount() {
        return coachExperienceAmount;
    }

    /**
     * @return the orderedAmount
     */
    public long getOrderedAmount() {
        return orderedAmount;
    }

    /**
     * @return the occurDate
     */
    public Date getOccurDate() {
        return occurDate;
    }

    /**
     * @return the site
     */
    public Site getSite() {
        return site;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param visitAmount the visitAmount to set
     */
    public void setVisitAmount(long visitAmount) {
        this.visitAmount = visitAmount;
    }

    /**
     * @param experienceAmount the experienceAmount to set
     */
    public void setExperienceAmount(long experienceAmount) {
        this.experienceAmount = experienceAmount;
    }

    /**
     * @param coachExperienceAmount the coachExperienceAmount to set
     */
    public void setCoachExperienceAmount(long coachExperienceAmount) {
        this.coachExperienceAmount = coachExperienceAmount;
    }

    /**
     * @param orderedAmount the orderedAmount to set
     */
    public void setOrderedAmount(long orderedAmount) {
        this.orderedAmount = orderedAmount;
    }

    /**
     * @param occurDate the occurDate to set
     */
    public void setOccurDate(Date occurDate) {
        this.occurDate = occurDate;
    }

    /**
     * @param site the site to set
     */
    public void setSite(Site site) {
        this.site = site;
    }

}
